
package com.work.pdf;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;

public class PdfHeaderDecorator extends PdfDecorator {

	private PdfWriter writer;

	private PdfHeaderDecorator(Document document) {
		super(document);

	}

	public PdfHeaderDecorator(Document document, PdfWriter writer) {
		super(document);
		this.writer = writer;

	}

	@Override
	public void decorate() throws DocumentException {
		//PageNumbersEventHelper events = new PageNumbersEventHelper();
		//HeaderAndFooter events = new HeaderAndFooter();
		//writer.setPageEvent(events);
	}

	/*public class PageNumbersEventHelper extends PdfPageEventHelper {
		PdfTemplate m_Template;
		BaseFont m_BaseFont;
		PdfContentByte m_Cb;

		public void onStartPage(PdfWriter arg0, Document arg1) {
		}

		public void onOpenDocument(PdfWriter writer, Document document) {
			try {
				m_BaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
			} catch (Exception e) {
				e.printStackTrace();
			}
			m_Cb = writer.getDirectContent();
			m_Template = m_Cb.createTemplate(80, 80);
		}

		public void onEndPage(PdfWriter writer, Document document) {
			int page = writer.getPageNumber();
			String text = String.valueOf(page);

			m_Cb.beginText();
			m_Cb.setFontAndSize(m_BaseFont, 8);
			m_Cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, 20, 20, 20);
			m_Cb.endText();
			m_Cb.addTemplate(m_Template, 302.3f, 20);
		}

		public void onCloseDocument(PdfWriter writer, Document document) {
			m_Template.beginText();
			m_Template.setFontAndSize(m_BaseFont, 8);
			String text = " / " + String.valueOf(writer.getPageNumber() - 1);
			m_Template.showTextAligned(PdfContentByte.ALIGN_LEFT, text, 0, 0, 0);
			m_Template.endText();
		}
	}

	public class HeaderAndFooter extends PdfPageEventHelper {

		protected Phrase header;

		protected PdfPTable footer;

		public HeaderAndFooter() {

			header = new Phrase("**** Header ****");
			footer = new PdfPTable(1);
			footer.setTotalWidth(150);
			footer.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
			footer.addCell(new Phrase(new Chunk("**** Footer summary Report generated by JavaGenious****").setAction(new PdfAction(PdfAction.FIRSTPAGE))));

		}

		public void onEndPage(PdfWriter writer, Document document) {
			PdfContentByte cb = writer.getDirectContent();
			ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(String.format("%d", writer.getPageNumber()), PdfUtils.FONT_TIMES_10_BOLD_BLACK), (document
			.right() - document.left())/ 2 + document.leftMargin(), document.top() + 10, 0);

			footer.writeSelectedRows(0, -1, (document.right() - document.left() - 300) / 2

			+ document.leftMargin(), document.bottom() - 10, cb);

		}

	} */
}
